package mylibrary.serialize;

import java.io.ObjectInputStream;
import java.io.ObjectInputStream.GetField;
import java.io.ObjectOutputStream;
import java.io.ObjectOutputStream.PutField;
import java.io.Serializable;

public class TestSerial implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public byte version = 100;
	public byte count = 0;
	public byte getVersion() {
		return version;
	}
	public void setVersion(byte version) {
		this.version = version;
	}
	public byte getCount() {
		return count;
	}
	public void setCount(byte count) {
		this.count = count;
	}
	
	private void writeObject(ObjectOutputStream out) {
		try {
			//PutField putFields = out.putFields();
			//System.out.println("old version: " + version);
			
			//version = 110;
			//putFields.put("version", version);
			//out.writeFields();
			
			
			version = 110;
			out.defaultWriteObject();
			System.out.println("old version: " + version);
			
			
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void readObject(ObjectInputStream in) {
		try {
			
			//GetField getFields = in.readFields();
			
			//byte ini = 0;
			//byte obj = getFields.get("version", ini);
			//System.out.println("get version: " + obj);
			
			//System.out.println("get version: " + version);
			
			//version = 5;
			
			in.defaultReadObject();
			version = 100;
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
